<div class="ketquas form">
<?php echo $this->Form->create('Ketqua');?>

	
        <?php
      echo "<select name='idphieu' onchange=\"document.getElementById('co_doi_gia_tri').value='true'; this.form.submit()\">";
       echo "<option>Xin hãy chọn Phiếu Kiểm Kê</option>";
        foreach($phieukiemkes as $phieukiemke)
        {
         $tenphieu=$phieukiemke['Phieukiemke']['tenphieu'];
         $phieukiemke_id=$phieukiemke['Phieukiemke']['id'];  
        echo "Chọn Phiếu Kiểm Kê :";
        echo "<option value=$phieukiemke_id>";
        echo $tenphieu;
        echo "</option>";
        }
      echo '</select>';
        //<input type='text' name='phieuid'/>".$."</td>/>6;
      //debug($idphieu);
          ?>
         <input  type="hidden" name="co_doi_gia_tri" id="co_doi_gia_tri" value="" />
          
    <?php   
     foreach($noidungs as $noidung)
     {
        $id[] = $noidung['Noidung']['id'];
        $ten[] = $noidung['Noidung']['chitiet'];
        $cha[] = ($noidung['Noidung']['noidung_id']=='')?NULL:$noidung['Noidung']['noidung_id'];
        $slcon[] = count($noidung['Noidung'])-5;
     } 
     ?>
     <?php $formN = "";?>
<?php  $formN.='<table id="phieu">'; ?>
<?php
 $formN.= "<tr class='dong-dau noidung'><td class='nhan noidung'>STT</td><td class='nhan noidung tenthietbi'>Tên Sản Phẩm</td>";
$i=0;
foreach ($noidungs as $noidung)
{
	if ($cha[$i] == NULL)
	{
			$formN.= "<td class='nhan noidung' colspan=$slcon[$i]>" . $ten[$i] . '</td>';
	}
    $i++;
}
$formN.= '<tr class=\'dong-dau noidung\'><td class=\'nhan noidung\'></td><td class=\'nhan noidung tenthietbi\'></td>';
$j=0;
foreach ($noidungs as $noidung)
{
	if ($cha[$j] != NULL and $slcon[$j]==0)
    {
        
       	$formN.= '<td class=\'nhan noidung\'>' . $ten[$j] . '</td>';
    }
		elseif($cha[$j] == NULL and $slcon[$j]!=0)
        {
            $j++;
            continue;
        }
			else
            {
               $formN.= '<td class=\'nhan noidung\'></td>'; 
            }
   $j++;     
}
$formN.= '</tr>';
  
$stt = 1;

foreach ($thietbis as $id_thietbi=>$thietbi)
{	
    $k=0;
	$formN.= '<tr class="dong-trong"><td class="hang-doc stt">' . $stt . '</td><td class="hang-doc thietbi tenthietbi">' . $thietbi . '</td>';  
	foreach ($noidungs as $noidung)
	{
    	if($slcon[$k]==0)
        {
             $formN.= "<td class='dong-trong dulieu'><input type='text' name='data[". $id_thietbi ."][" . $noidung['Noidung']['id'] . "]'/></td>";
    		// $data[$thietbi][$noidung] = '.'; //<-- Bien Data chi dung sau khi submit
        }
      	$k++;
    }
	$stt++;
    $formN.= '</tr>';
}

$formN.= '</table>';
print $formN;
 ?> 
 
 <?php 
 if(!empty($ans)){
                echo "<input type='hidden' name='bienan' value=$ans >"  ;    
                }
 
 if(!empty($kk)){
                echo "<input type='hidden' name='kk' value=$kk >"  ;    
                }  
 echo "<textarea style='display: none' name='bien_trung_gian'>$formN</textarea>"  ;    
                     
 ?>
 

<?php echo $this->Form->end(__('Lưu', true));?>
</div> 

</div>
